package com.pyb.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Callable;

import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.strands.SuspendableCallable;

/**
 * FiberUtil
 *
 * @author chuchen.zhang
 * @date 17-2-28 上午12:29
 */
public class FiberUtil {

	private static final Logger logger = LoggerFactory.getLogger(FiberUtil.class);

	public static <T> T execute(final SuspendableCallable<T> call) {
		try {
			Fiber<T> fiber = new Fiber<T>(call).start();
			return fiber.get();
		} catch (Exception e) {
			logger.error("fiber execute error", e);
		}
		return null;
	}
}
